﻿using System.Threading.Tasks;

namespace Sidvall.AuthorizationManager.Model.Remote.DataPortalManagers
{
    public static partial class AuthorizationScopeExportManager
    {
        #region DeleteItemsAsync

        static partial void OnBeforeDelete(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        static partial void OnAfterDelete(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task DeleteItemsAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<int, global::Sidvall.Data.DeleteCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeDelete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/DeleteItems");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        dataPortalContext.ResultValueItem = await result.GetContentResolvedAsync<int>().ConfigureAwait(false);
                    }
                    OnAfterDelete(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region NewItemAsync

        static partial void OnBeforeNewItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        static partial void OnAfterNewItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        public static async Task NewItemAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.CreateCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeNewItem(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/NewItem");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        var data = await result.GetContentResolvedAsync<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExport>().ConfigureAwait(false);
                        if (data != null)
                            dataPortalContext.ResultValueItem = dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.Copy(data, Sidvall.Data.CopySettings.FullCopyCurrent(Sidvall.Data.DataRowContextOption.None, Sidvall.Data.DataRowState.Added));
                        else
                            dataPortalContext.ResultValueItem = null;
                    }
                    OnAfterNewItem(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region NewItemsAsync

        static partial void OnBeforeNewItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        static partial void OnAfterNewItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.CreateCriteria> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task NewItemsAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.CreateCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeNewItems(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/NewItems");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        var data = await result.GetContentResolvedAsync<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExportCollectionItem>().ConfigureAwait(false);
                        if (data != null)
                            dataPortalContext.ResultValueListProvider = dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.Copy(data.Items, Sidvall.Data.CopySettings.FullCopyCurrent(Sidvall.Data.DataRowContextOption.None, Sidvall.Data.DataRowState.Added));
                        else
                            dataPortalContext.ResultValueListProvider = null;
                    }
                    OnAfterNewItems(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region GetItemAsync

        static partial void OnBeforeGetItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeExportRelation>> dataPortalContext);
        static partial void OnAfterGetItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeExportRelation>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task GetItemAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.FetchCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeExportRelation>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeGetItem(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/GetItem");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        var data = await result.GetContentResolvedAsync<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExport>().ConfigureAwait(false);
                        if (data != null)
                            dataPortalContext.ResultValueItem = dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.Copy(data, Sidvall.Data.CopySettings.FullCopyCurrent(Sidvall.Data.DataRowContextOption.None, Sidvall.Data.DataRowState.Unchanged));
                        else
                            dataPortalContext.ResultValueItem = null;
                    }
                    OnAfterGetItem(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region GetItemsAsync

        static partial void OnBeforeGetItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeExportRelation>> dataPortalContext);
        static partial void OnAfterGetItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeExportRelation>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task GetItemsAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, global::Sidvall.Data.FetchListCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField, global::Sidvall.AuthorizationManager.Data.Relations.AuthorizationScopeExportRelation>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeGetItems(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/GetItems");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        var data = await result.GetContentResolvedAsync<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExportCollectionItem>().ConfigureAwait(false);
                        if (data != null)
                            dataPortalContext.ResultValueListProvider = dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.Copy(data.Items, Sidvall.Data.CopySettings.FullCopyCurrent(Sidvall.Data.DataRowContextOption.None, Sidvall.Data.DataRowState.Unchanged));
                        else
                            dataPortalContext.ResultValueListProvider = (Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>)dataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeExport);
                    }
                    OnAfterGetItems(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region GetItemCountAsync

        static partial void OnBeforeGetItemCount(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        static partial void OnAfterGetItemCount(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task GetItemCountAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<long, global::Sidvall.Data.FetchCountCriteria<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeGetItemCount(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/GetItemCount");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        dataPortalContext.ResultValueItem = await result.GetContentResolvedAsync<long>().ConfigureAwait(false);
                    }
                    OnAfterGetItemCount(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region SaveItemAsync

        static partial void OnBeforeSaveItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>> dataPortalContext);
        static partial void OnAfterSaveItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task SaveItemAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>> dataPortalContext)
        {
            global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport data;

            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeSaveItem(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var saveContext = new Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExport>()
                        {
                            Settings = dataPortalContext.OperationContext.Settings
                        };
                        if (dataPortalContext.OperationContext.GetSaveMode() != Sidvall.Data.SaveMode.Default)
                            saveContext.Item = global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.Copy(dataPortalContext.OperationContext.Item, Sidvall.Data.CopySettings.FullCopyAll(Sidvall.Data.DataRowContextOption.StateAndKey, null));
                        else
                            saveContext.Item = global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.Copy(dataPortalContext.OperationContext.Item, Sidvall.Data.CopySettings.FullCopyModified(Sidvall.Data.DataRowContextOption.StateAndKey, null));
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/SaveItem");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(saveContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        data = await result.GetContentResolvedAsync<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExport>().ConfigureAwait(false);
                        if (data != null)
                        {
                            dataPortalContext.ResultValueItem = dataPortalContext.OperationContext.Item;
                            dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.Import(dataPortalContext.ResultValueItem, data, Sidvall.Data.CopySettings.FullMergeAll(Sidvall.Data.DataRowContextOption.None, null));
                            dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.AcceptChanges(dataPortalContext.ResultValueItem, dataPortalContext.AcceptChangesSettings);
                        }
                    }
                    OnAfterSaveItem(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region SaveItemsAsync

        static partial void OnBeforeSaveItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>> context);
        static partial void OnBeforeSaveItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>>> dataPortalContext);
        static partial void OnAfterSaveItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task SaveItemsAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport, Sidvall.Data.SaveContext<Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>>> dataPortalContext)
        {
            global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExportCollectionItem data;

            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeSaveItems(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var saveContext = new Sidvall.Data.SaveContext<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExportCollectionItem>()
                        {
                            Settings = dataPortalContext.OperationContext.Settings
                        };
                        if (dataPortalContext.OperationContext.GetSaveMode() != Sidvall.Data.SaveMode.Default)
                            saveContext.Item = global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.Copy(dataPortalContext.OperationContext.Item.DataItems, Sidvall.Data.CopySettings.FullCopyAll(Sidvall.Data.DataRowContextOption.StateAndKey, null));
                        else
                            saveContext.Item = global::Sidvall.AuthorizationManager.SystemContext.Current.EntityFacade.AuthorizationScopeExportManager.Copy(dataPortalContext.OperationContext.Item.DataItems, Sidvall.Data.CopySettings.FullCopyModified(Sidvall.Data.DataRowContextOption.StateAndKey, null));
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/SaveItems");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(saveContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        data = await result.GetContentResolvedAsync<global::Sidvall.AuthorizationManager.Net.Services.V1.AuthorizationScopeExportCollectionItem>().ConfigureAwait(false);
                        if (data != null)
                        {
                            dataPortalContext.ResultValueListProvider = dataPortalContext.OperationContext.Item;
                            dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.Import(dataPortalContext.ResultValueList, data.Items, Sidvall.Data.CopySettings.FullMergeAll(Sidvall.Data.DataRowContextOption.None, null));
                            dataPortalManager.GenericEntityFacade.AuthorizationScopeExportManager.AcceptChanges(dataPortalContext.ResultValueList, dataPortalContext.AcceptChangesSettings);
                        }
                        else if (dataPortalContext.Result != Sidvall.Business.DataPortalResult.Ok)
                        {
                            dataPortalContext.ResultValueListProvider = (Sidvall.Data.IDataRowProvider<global::Sidvall.AuthorizationManager.Data.IAuthorizationScopeExport>)dataPortalManager.ResourceFactory.CreateItems(global::Sidvall.AuthorizationManager.Data.Model.DomainObjects.AuthorizationScopeExport);
                        }
                    }
                    OnAfterSaveItems(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region UpdateItemAsync

        static partial void OnBeforeUpdateItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<bool, Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        static partial void OnAfterUpdateItem(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<bool, Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task UpdateItemAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<bool, Sidvall.Data.UpdateItemContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeUpdateItem(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/UpdateItem");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        dataPortalContext.ResultValueItem = await result.GetContentResolvedAsync<bool>().ConfigureAwait(false);
                    }
                    OnAfterUpdateItem(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region UpdateItemsAsync

        static partial void OnBeforeUpdateItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        static partial void OnAfterUpdateItems(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext);
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public static async Task UpdateItemsAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<int, Sidvall.Data.UpdateItemsContext<global::Sidvall.AuthorizationManager.Data.Fields.AuthorizationScopeExportField>> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeUpdateItems(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/UpdateItems");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        dataPortalContext.ResultValueItem = await result.GetContentResolvedAsync<int>().ConfigureAwait(false);
                    }
                    OnAfterUpdateItems(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
        #region ExecuteAsync

        static partial void OnBeforeExecute(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext);
        static partial void OnAfterExecute(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext);
        public static async Task ExecuteAsync(global::Sidvall.AuthorizationManager.Model.IDataPortalManager dataPortalManager, global::Sidvall.Business.DataPortalContext<global::Sidvall.Data.CommandCriteria, global::Sidvall.Data.CommandCriteria> dataPortalContext)
        {
            if (dataPortalContext == null)
                throw new System.ArgumentNullException(nameof(dataPortalContext));
            do
            {
                try
                {
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvoke(dataPortalManager, dataPortalContext);
                    OnBeforeExecute(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                    if (dataPortalContext.Result == Sidvall.Business.DataPortalResult.None)
                    {
                        var webAddress = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetWebAddress(dataPortalContext, "api/V1/AuthorizationScopeExport/Execute");
                        var content = Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataPortalContext.OperationContext);
                        var client = global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetHttpClient(dataPortalContext);
                        var result = await global::Sidvall.AuthorizationManager.SystemContext.Current.DataPortalStrategy.GetResultAsync(dataPortalContext, client, webAddress, content).ConfigureAwait(false);
                        dataPortalContext.ResultValueItem = await result.GetContentResolvedAsync<global::Sidvall.Data.CommandCriteria>().ConfigureAwait(false);
                    }
                    OnAfterExecute(dataPortalManager, dataPortalContext);
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalInvokeComplete(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync().ConfigureAwait(false);
                }
                catch (System.Exception ex)
                {
                    dataPortalContext.Exception = ex;
                    global::Sidvall.AuthorizationManager.Model.Remote.DataPortalEventManager.DataPortalException(dataPortalManager, dataPortalContext);
                    await dataPortalContext.DoTaskAsync(!dataPortalContext.Retry).ConfigureAwait(false);
                }
            } while (dataPortalContext.DoRetry());
        }

        #endregion
    }
}